<head><title>Please wait ...</title>
<script type="text/javascript">
<!--
function fail(message){
	alert(message);
	self.location.href="/register.html";
}
//-->
</script>
<?php
$con=mysql_connect("localhost","William");

if (!$con){
	die("MySQL Error " . mysql_error());
}
mysql_select_db("osa", $con);
$success=false;
$user=$_REQUEST["user"];
$query=mysql_query("SELECT * FROM user WHERE username='$user'",$con);
if(!$query) die("MySQL Error " . mysql_error());
$row=mysql_fetch_array($query);
$nick=$_REQUEST["nick"];
if(strlen($nick)==0) $nick="OSAer";
if($row)
	echo "</head><body onLoad='fail(\"User $user already exists!\")' />";
else{
	$query=mysql_query("INSERT INTO user VALUES (NULL, '$user', 'normal', '$nick', 50, '". $_REQUEST["pwd"] . "')");
	if(!$query) die("MySQL Error " . mysql_error());
	$success=true;
}
if($success) echo "<meta http-equiv='Refresh' content='5;url=/index.html'></head>
<body>Register success.<br />
You will be redirected to the login page in 5 seconds ...
Click <a href='/index.html'>here</a> to go to the login page immediately.</body>";
mysql_close($con);
?>	
